<?php

namespace backend\modules\personnel\controllers;

use common\models\base\SearchModel;
use common\models\personnel\ByProject;
use common\traits\Curd;
use Yii;
use backend\controllers\BaseController;

/**
 * Class ByProject
 * @package backend\modules\project\controllers
 */
class ByProjectController extends BaseController
{
    use Curd;

    public $modelClass = ByProject::class;

    /**
     * 首页
     * @return string
     */
    public function actionIndex(){
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            'partialMatchAttributes' => ['name','desc','user'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);
        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
        ]);
    }

    /**
     * 富文本字符串截取
     * @param $string
     * @return string
     */
    public static function Intercept($string)
    {
        //把一些预定义的 HTML 实体转换为字符
        $html_string = htmlspecialchars_decode($string);
        //将空格替换成空
        $content = str_replace(" ", "", $html_string);
        //函数剥去字符串中的 HTML、XML 以及 PHP 的标签,获取纯文本内容
        $contents = strip_tags($content);
        //返回字符串中的前80字符串长度的字符
        $text = mb_substr($contents, 0, 400, "utf-8");
        return $text.'……';
    }


}
